<template>
  <div class="u-p-20">
    <el-card shadow="never">
      <div slot="header">
        <span>
          <b class="u-f-16">代理商列表</b>
        </span>
      </div>

      <el-form :inline="true" :model="queryForm" size="small" class="u-text-center">
        <el-form-item label="处理状态">
          <el-select v-model="queryForm.handle_status" clearable>
            <el-option label="全部" value></el-option>
            <el-option label="同意" value="2"></el-option>
            <el-option label="未处理" value="1"></el-option>
            <el-option label="拒绝" value="3"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="代理商名称">
          <el-input v-model="queryForm.keyword" placeholder="输入代理商名称" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="getPageData(true)">查询</el-button>
        </el-form-item>
      </el-form>

      <el-table :data="tableData" class="u-mt-10" v-viewer>
        <el-table-column label="id" prop="id" width="80"></el-table-column>
        <el-table-column label="添加时间" prop="add_date"></el-table-column>
        <el-table-column label="代理商图片">
          <template slot-scope="scope">
            <el-image
              style="max-width: 50px;"
              :src="scope.row.agency_img"
              :data-src="scope.row.agency_img"
              fit="cover"
              lazy
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column label="代理商名称" prop="agency_title"></el-table-column>
        <el-table-column label="总价" prop="order_total"></el-table-column>
        <el-table-column label="处理状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.handle_status==3" type="success">拒绝</el-tag>
             <el-tag v-if="scope.row.handle_status==2" type="success">同意</el-tag>
            <el-tag v-else type="warning">未处理</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="备注" prop="remark"></el-table-column>
        <el-table-column label="操作" width="120">
          <template slot-scope="scope">
            <el-dropdown>
              <span class="el-dropdown-link">
                操作
                <i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
               <el-dropdown-item
                  @click.native="handleRoute(scope.row.id,'agencyOrderEdit')"
                  v-if="hasPerm('agencyOrderEditBtn')"
                >
                  <el-button size="mini" type="text">查看/审核</el-button>
                </el-dropdown-item>
                  <el-dropdown-item
                  @click.native="confirmTake(scope.row.id)"
                  v-if="scope.row.handle_status==1"
                >
                  <el-button size="mini" type="text">取消订单</el-button>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>

      <div class="u-mt-20 u-text-center">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handlePageChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 40, 50]"
          :page-size="limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import commonPage from "@/mixins/common-page";
export default {
  mixins: [commonPage],
  data() {
    return {
      apiName: "agency",
      apiPage: "agencyOrderPage",
      queryForm: {
        handle_status: "",
        keyword: ""
      }
    };
  },
  methods: {
    handleStatus(id, handle_status) {
      //拼团状态
      var json = {
        id: id,
        handle_status: handle_status
      };
      this.$api[this.apiName].agencyOrderStatus(json).then(response => {
        if (response.code == 1) {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        }
      });
    }
  }
};
</script>
